<template>
  <div id="app">
    <my-process-designer
      v-if="1"
      :key="`designer-${reloadIndex}`"
      v-model="xmlString"
      v-bind="controlForm"
      keyboard
      ref="processDesigner"
      :prefix="controlForm.prefix"
      :saveFn="upload"
      @element-click="elementClick"
      @init-finished="initModeler"
    />

    <my-properties-panel
      v-if="1"
      :key="`penal-${reloadIndex}`"
      :bpmn-modeler="modeler"
      :prefix="controlForm.prefix"
      :idEditDisabled="controlForm.idEditDisabled"
      :initData="initData"
      :treeData="treeData"
      class="process-panel"
    />
    <my-process-veiwer v-if="0" ref="process-veiwer" v-model="xmlString" :line-data="highLine" />
  </div>
</template>

<script>
import translations from "@/translations";
// 自定义渲染（隐藏了 label 标签）
import CustomRenderer from "@/modules/custom-renderer";
// 自定义元素选中时的弹出菜单（修改 默认任务 为 用户任务）
import CustomContentPadProvider from "../package/process-designer/plugins/content-pad";
// 自定义左侧菜单（修改 默认任务 为 用户任务）
import CustomPaletteProvider from "../package/process-designer/plugins/palette";
// 自定义侧边栏
// import MyProcessPanel from "../package/process-panel/ProcessPanel";

import temp from "./temp";

export default {
  name: "App",
  components: {},
  data() {
    return {
      xmlString: "",
      modeler: null,
      reloadIndex: 0,
      controlDrawerVisible: false,
      translationsSelf: translations,
      controlForm: {
        processId: "", //流程id
        processName: "", //流程名称
        simulation: true,
        isEdit: false, //编辑模式 0  部署模式 1
        labelEditing: false, //标签编辑
        labelVisible: false, //标签隐藏
        prefix: "activiti",
        idEditDisabled: true, //是否允许编辑流程id
        headerButtonSize: "mini", //默认按钮样式
        additionalModel: [CustomContentPadProvider, CustomPaletteProvider]
      },
      addis: {}
    };
  },
  created() {
    console.group("初始化测试信息");
    this.highLine = temp.highLine; //高亮数据
    this.xmlString = temp.xmlString; //XML图模拟
    this.initData = temp.initData; //模拟初始化数据
    this.treeData = temp.treeData; //模拟树菜单
    console.groupEnd("初始化测试信息");
  },
  methods: {
    initModeler(modeler) {
      setTimeout(() => {
        this.modeler = modeler;
      }, 10);
    },
    reloadProcessDesigner() {
      this.controlForm.additionalModel = [];
      for (let key in this.addis) {
        if (this.addis[key]) {
          this.controlForm.additionalModel.push(this.addis[key]);
        }
      }
      this.reloadIndex += 1;
      this.modeler = null; // 避免 panel 异常
    },
    changeLabelEditingStatus(status) {
      this.addis.labelEditing = status ? { labelEditingProvider: ["value", ""] } : false;
      this.reloadProcessDesigner();
    },
    changeLabelVisibleStatus(status) {
      this.addis.customRenderer = status ? CustomRenderer : false;
      this.reloadProcessDesigner();
    },
    elementClick(element) {
      this.element = element;
    },
    upload(xmlstr) {
      //保存部署
      const reg = /<bpmndi:BPMNPlane id="(\S+)"/; //正则表达式
      const reptext = '<bpmndi:BPMNPlane id="BPMNPlane_1"'; //替换的文本
      let newXmlStr = xmlstr.replace(reg, reptext);
      console.log("最终生成的字符串:", newXmlStr);
    }
  }
};
</script>

<style lang="scss">
body {
  overflow: hidden;
  margin: 0;
  box-sizing: border-box;
}
#app {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  display: inline-grid;
  grid-template-columns: auto max-content;
}
.demo-control-bar {
  position: fixed;
  right: 8px;
  bottom: 8px;
  z-index: 1;
  .open-control-dialog {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    font-size: 32px;
    background: rgba(64, 158, 255, 1);
    color: #ffffff;
    cursor: pointer;
  }
}
.control-form {
  .el-radio {
    width: 100%;
    line-height: 32px;
  }
}
body,
body * {
  /* 滚动条 */
  &::-webkit-scrollbar-track-piece {
    background-color: #fff; /*滚动条的背景颜色*/
    border-radius: 0; /*滚动条的圆角宽度*/
  }
  &::-webkit-scrollbar {
    width: 10px; /*滚动条的宽度*/
    height: 8px; /*滚动条的高度*/
  }
  &::-webkit-scrollbar-thumb:vertical {
    /*垂直滚动条的样式*/
    height: 50px;
    background-color: rgba(153, 153, 153, 0.5);
    border-radius: 4px;
    outline: 2px solid #fff;
    outline-offset: -2px;
    border: 2px solid #fff;
  }
  &::-webkit-scrollbar-thumb {
    /*滚动条的hover样式*/
    background-color: rgba(159, 159, 159, 0.3);
    border-radius: 4px;
  }
  &::-webkit-scrollbar-thumb:hover {
    /*滚动条的hover样式*/
    background-color: rgba(159, 159, 159, 0.5);
    border-radius: 4px;
  }
}
</style>
